<!--治理类型明细-->
<template>
  <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick">
    <el-tab-pane :label="`计算 ${calcSize}`" name="first">
      <el-row :gutter="24">
        <el-col :span="3" v-for="(item,index) in valueList">
          <!--点击globalDetailList方法，展示治理详细信息-->
          <el-card class="box-card" @click.native="globalDetailList(item.optionCode)">
            <div style="font-size:14px;color:grey;font-weight: bold " :key="item.index">{{ item.optionDesc }}</div>
            <div style="font-size:12px;">{{item.governanceDetailSize }}</div>
            <!--            {{item.governanceDetailList}}-->
          </el-card>
        </el-col>
      </el-row>
      <el-table :data="governanceDetailList">
        <el-table-column
          prop="tableName"
          label="表名"
          width="300">
        </el-table-column>
        <el-table-column
          prop="governanceContent"
          label="描述"
          width="200">
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <el-pagination
        :current-page="page"
        :total="total"
        :page-size="limit"
        :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
        style="padding: 30px 0; text-align: center;"
        layout="sizes, prev, pager, next, jumper, ->, total, slot"
        @current-change="fetchData"
        @size-change="changeSize"
      />
    </el-tab-pane>
    <el-tab-pane :label="`存储 ${storageSize}`">
      <el-row :gutter="24">
        <el-col :span="3" v-for="(item,index) in valueList">
          <!--点击globalDetailList方法，展示治理详细信息-->
          <el-card class="box-card" style="height: 65px;width: 130px" @click.native="globalDetailList(item.optionCode)">
            <div style="font-size:14px;color:grey;font-weight: bold " :key="item.index">{{ item.optionDesc }}</div>
            <div style="font-size:12px;">{{ item.governanceDetailSize }}</div>
            <!--            {{item.governanceDetailList}}-->
          </el-card>
        </el-col>
      </el-row>
      <el-table :data="governanceDetailList">
        <el-table-column
          prop="tableName"
          label="表名"
          width="300">
        </el-table-column>
        <el-table-column
          prop="governanceContent"
          label="描述"
          width="200">
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <el-pagination
        :current-page="page"
        :total="total"
        :page-size="limit"
        :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
        style="padding: 30px 0; text-align: center;"
        layout="sizes, prev, pager, next, jumper, ->, total, slot"
        @current-change="fetchData"
        @size-change="changeSize"
      />
    </el-tab-pane>
    <el-tab-pane :label="`规范 ${specSize}`">
      <el-row :gutter="24">
        <el-col :span="3" v-for="(item,index) in valueList">
          <!--点击globalDetailList方法，展示治理详细信息-->
          <el-card class="box-card" style="height: 65px;width: 130px" @click.native="globalDetailList(item.optionCode)">
            <div style="font-size:14px;color:grey;font-weight: bold " :key="item.index">{{ item.optionDesc }}</div>
            <div style="font-size:12px;">{{ item.governanceDetailSize }}</div>
            <!--            {{item.governanceDetailList}}-->
          </el-card>
        </el-col>
      </el-row>
      <el-table :data="governanceDetailList">
        <el-table-column
          prop="tableName"
          label="表名"
          width="300">
        </el-table-column>
        <el-table-column
          prop="governanceContent"
          label="描述"
          width="200">
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <el-pagination
        :current-page="page"
        :total="total"
        :page-size="limit"
        :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
        style="padding: 30px 0; text-align: center;"
        layout="sizes, prev, pager, next, jumper, ->, total, slot"
        @current-change="fetchData"
        @size-change="changeSize"
      />
    </el-tab-pane>
    <el-tab-pane :label="`安全 ${securitySize}`">
      <el-row :gutter="24">
        <el-col :span="3" v-for="(item,index) in valueList">
          <!--点击globalDetailList方法，展示治理详细信息-->
          <el-card class="box-card" style="height: 65px;width: 130px" @click.native="globalDetailList(item.optionCode)">
            <div style="font-size:14px;color:grey;font-weight: bold " :key="item.index">{{ item.optionDesc }}</div>
            <div style="font-size:12px;">{{ item.governanceDetailSize }}</div>
          </el-card>
        </el-col>
      </el-row>
      <el-table :data="governanceDetailList">
        <el-table-column
          prop="tableName"
          label="表名"
          width="300">
        </el-table-column>
        <el-table-column
          prop="governanceContent"
          label="描述"
          width="200">
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <el-pagination
        :current-page="page"
        :total="total"
        :page-size="limit"
        :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
        style="padding: 30px 0; text-align: center;"
        layout="sizes, prev, pager, next, jumper, ->, total, slot"
        @current-change="fetchData"
        @size-change="changeSize"
      />
    </el-tab-pane>
    <el-tab-pane :label="`质量 ${qualitySize}`">
      <el-row :gutter="24">
        <el-col :span="3" v-for="(item,index) in valueList">
          <!--点击globalDetailList方法，展示治理详细信息-->
          <el-card class="box-card" style="height: 65px;width: 130px" @click.native="globalDetailList(item.optionCode)">
            <div style="font-size:14px;color:grey;font-weight: bold " :key="item.index">{{ item.optionDesc }}</div>
            <div style="font-size:12px;">{{ item.governanceDetailSize }}</div>
          </el-card>
        </el-col>
      </el-row>
      <el-table :data="governanceDetailList">
        <el-table-column
          prop="tableName"
          label="表名"
          width="300">
        </el-table-column>
        <el-table-column
          prop="governanceContent"
          label="描述"
          width="200">
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <el-pagination
        :current-page="page"
        :total="total"
        :page-size="limit"
        :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
        style="padding: 30px 0; text-align: center;"
        layout="sizes, prev, pager, next, jumper, ->, total, slot"
        @current-change="fetchData"
        @size-change="changeSize"
      />
    </el-tab-pane>
  </el-tabs>
</template>
<script>
import api from '@/api/govern/govern'
import {parseTime} from '@/utils'

const now = parseTime(new Date(new Date().getTime()), '{y}-{m}-{d}')
export default {
  data() {
    return {
      activeName: 'first',
      scoreList: [],
      calcSize: 0,//计算
      storageSize: 0,//存储
      specSize: 0,//规范
      securitySize: 0,//安全
      qualitySize: 0,//质量,
      valueList: [],
      total: 0, // 数据库中的总记录数
      page: 1, // 默认页码
      limit: 10, // 每页记录数
      governanceDetailList: [],
      optionCode: "",

    };
  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.getGlobalScore()
    },
    //获取各个治理类型的分数
    getGlobalScore() {
      api.globalScore().then((response) => {
        console.log(" res:" + response.data.scoreList)
        this.globalSize = response.data.scoreList
        this.calcSize = response.data.scoreList[0]
        this.storageSize = response.data.scoreList[1]//存储
        this.specSize = response.data.scoreList[2]//规范
        this.securitySize = response.data.scoreList[3]//安全
        this.qualitySize = response.data.scoreList[4]//质量
      })
        .catch((response) => {
          console.log("失败" + response);
          // Vue.$message.error('服务器错误，请稍后再试')
          //reject(response)
        });
    },
    //根据治理类型获取细节条数
    handleClick(tab, event) {
      if (tab.index == 0) {
        //计算
        api.governanceOptions("calc").then((response) => {
          console.log(" res:" + response)
          this.valueList = response.data
        })
          .catch((response) => {
            console.log("失败" + response);
            // Vue.$message.error('服务器错误，请稍后再试')
            //reject(response)
          });
      } else if (tab.index == 1) {
        //存储
        api.governanceOptions("storage").then((response) => {
          console.log(" res:" + response)
          this.valueList = response.data
        })
          .catch((response) => {
            console.log("失败" + response);
            // Vue.$message.error('服务器错误，请稍后再试')
            //reject(response)
          });
      } else if (tab.index == 2) {
        //规范
        api.governanceOptions("spec").then((response) => {
          console.log(" res:" + response)
          this.valueList = response.data

        })
          .catch((response) => {
            console.log("失败" + response);
            // Vue.$message.error('服务器错误，请稍后再试')
            //reject(response)
          });

      } else if (tab.index == 3) {
        //安全
        api.governanceOptions("security").then((response) => {
          console.log(" res:" + response)
          this.valueList = response.data
        })
          .catch((response) => {
            console.log("失败" + response);
            // Vue.$message.error('服务器错误，请稍后再试')
            //reject(response)
          });
      } else if (tab.index == 4) {
        //质量
        api.governanceOptions("quality").then((response) => {
          console.log(" res:" + response)
          this.valueList = response.data
        })
          .catch((response) => {
            console.log("失败" + response);
            // Vue.$message.error('服务器错误，请稍后再试')
            //reject(response)
          });
      }
      console.log(tab, event);
    },
    // 当页码发生改变的时候
    changeSize(size) {
      console.log(size)
      this.limit = size
      this.fetchData(1)
    },

    //点击时间
    globalDetailList(optionCode) {
      this.optionCode = optionCode
      this.fetchData(1)
    },
    // 加载banner列表数据
    fetchData(page = 1) {
      console.log('翻页。。。' + page)
      // 异步获取远程数据（ajax）
      this.page = page
      /**
       * 查看治理细节下所有信息
       */
      api.globalDetailList(this.optionCode, this.page, this.limit).then(response => {
        console.log("-----" + this.optionCode)
        this.listLoading = true
        this.governanceDetailList = response.data.records
        console.log("========tableData" + this.governanceDetailList)
        this.total = response.data.total
        this.listLoading = false

      })
    }
  }
}
</script>



